//
//  IndexViewController.m
//  HaierGMS_APP
//
//  Created by 堂堂 on 16/6/30.
//  Copyright © 2016年 堂堂. All rights reserved.
//

#import "IndexViewController.h"
#import "DownLoadDbTool.h"
#import <sqlite3.h>
#import "AFHTTPRequestOperationManager.h"
#import "Base64Until.h"
@interface IndexViewController ()

@end

@implementation IndexViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSLog(@"初始化成功");
    
    DownLoadDbTool * download = [[DownLoadDbTool alloc]init];
    BOOL flag = [download downLoadDb];
    if (flag) {
        NSLog(@"复制成功");
        
        NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingString:@"city.db"];
        // 是否打开成功
        
        
        sqlite3 * database;
        
        if (sqlite3_open([path UTF8String], &database) == SQLITE_OK)
        {
            NSLog(@"打开数据库成功");
            
            char *const sql = "SELECT city,code FROM location_t";
            char *const sql2 = "select name from sqlite_master ";
            char *const sql4 = "SELECT name FROM t_person";
            sqlite3_stmt *statement;
            
            int result = sqlite3_prepare_v2(database, sql2, -1, &statement, NULL);
            if (result == SQLITE_OK) {
                while (sqlite3_step(statement) == SQLITE_ROW) {
                    
                    const unsigned char *name = sqlite3_column_text(statement, 0);
                    //const unsigned char *code = sqlite3_column_text(statement, 1);
                    
                    
                    NSLog(@"%@",[NSString stringWithUTF8String:(const char *) name]);
                    //NSLog(@"%@",[NSString stringWithUTF8String:(const char *) code]);
                }
            }
        }
        else
        {
            // 打开数据库失败
            sqlite3_close(database);
            NSAssert1(0, @"Failed to open database: '%s'.", sqlite3_errmsg(database));
        }
        
        
        
    }else{
        NSLog(@"复制失败");

    }
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    NSDictionary *dict = @{@"JOB_NO": @"60532001005"};
  
    
   // NSArray *array = @[dict];
    // 设置请求格式
   // manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager POST:@"http://115.28.167.17:8131/RMTWS.asmx/GET_UpdatingUrl_SMT" parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        
        NSLog(@"%@", result);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"调用失败");
    }];
    

    //加密
   // NSString *str = @"AA21f0c1762a3abc299c013abe7dbcc50001DD";
    
   // NSData* bytes = [str dataUsingEncoding:NSUTF8StringEncoding];
    
    
   // Byte * myByte = (Byte *)[bytes bytes];
    
    
    NSMutableString *sb= [[NSMutableString alloc]init];

    [sb appendString:@"12345"];
    
    [sb deleteCharactersInRange:NSMakeRange(4,1)];
    //NSLog(@"%@",str1);
    [sb insertString:@"＝" atIndex:4];
   
    NSLog(@"%@",sb);
    }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
